import React from 'react';
import ReactDOM from 'react-dom';

/* class index extends Component {
  render() {
    return <div></div>;
  }
} */
function Test() {
  console.log('test');
  console.log(React.useState(1));
  const [msg, setData] = React.useState(1)
  const [name,setName]=React.useState('carlos')
  React.useEffect(()=>{
    console.log('执行了这个钩子');
    let timer=setInterval(()=>{
      setData(state=>state+1)
    },1000)
    return (()=>{
      clearInterval(timer)
    })
  },[name])
  function add() {
    setData(100)
  }
  function changeName(){
    setName('carlos2')
  }
  function myUnmount(){
    ReactDOM.unmountComponentAtNode(document.getElementById('root'))
  }
  return (
    <div>
      test
      <h3>{msg}</h3>
      <button onClick={add}>button</button>
      <button onClick={changeName}>button</button>
      <button onClick={myUnmount}>卸载</button>
    </div>
  )
}
export default Test
